package com.tank.game.core.play;

import com.tank.game.api.Play;
import com.tank.game.api.Tank;

import java.util.Objects;

/**
 * 抽象的玩家
 *
 * @author Zed
 */
public abstract class AbstractPlay implements Play {

    private String id;

    private Tank tank;

    private PlayConfig playConfig;

    public AbstractPlay(DefaultPlayBuilder builder) {
        this.id = Objects.requireNonNull(builder.getId(), "\"id\" cannot be null.");
        this.tank = builder.getTank() == null ? createTank() : builder.getTank();
        //TODO 异常处理
        this.playConfig = builder.getPlayConfig();
    }

    /**
     * 如果外部传进来得为空那么久进行创建
     *
     * @return {@link Tank}
     */
    protected abstract Tank createTank();

    @Override
    public void setTank(Tank tank) {
        this.tank = tank;
    }

    @Override
    public String getId() {
        return this.id;
    }

    @Override
    public Tank getTank() {
        return this.tank;
    }

    public PlayConfig getPlayConfig() {
        return playConfig;
    }
}
